#include "ustc_comdef.h"
#include "ustc_custom.h"
#include "ramdisk.h"


RAM_DISK_T g_ramdisk;

/******************************************************************************
 * FUNCTION:    ramdisk_init
 *
 * DESCRIPTION: 
 *              
 * Inputs:      
 *              unsigned long *buf
 *              unsigned long size
 * Outputs:     
 *              
 * Return:      
 *              
 * Notes:       
 *              
 ******************************************************************************/
void ramdisk_init(unsigned long *buf, unsigned long size)
{
	g_ramdisk.blk=(RAM_DISK_BLK_T*)buf;
	g_ramdisk.blk_cnt=size/512;
}

/******************************************************************************
 * FUNCTION:    ramdisk_read
 *
 * DESCRIPTION: 
 *              
 * Inputs:      
 *              unsigned long *buf
 *              unsigned long lba
 *              unsigned long cnt
 * Outputs:     
 *              
 * Return:      
 *              
 * Notes:       
 *              
 ******************************************************************************/
USTC_U16 ramdisk_read(unsigned long *buf, unsigned long lba, unsigned long cnt)
{
	ustc_memcpy_32(buf, g_ramdisk.blk+lba, cnt*512/4);

	return 0;
}

/******************************************************************************
 * FUNCTION:    ramdisk_write
 *
 * DESCRIPTION: 
 *              
 * Inputs:      
 *              unsigned long * buf
 *              unsigned long lba
 *              unsigned long cnt
 * Outputs:     
 *              
 * Return:      
 *              
 * Notes:       
 *              
 ******************************************************************************/
USTC_U16 ramdisk_write(unsigned long * buf, unsigned long lba, unsigned long cnt)
{
	ustc_memcpy_32(g_ramdisk.blk+lba, buf, cnt*512/4);

	return 0;
}

/******************************************************************************
 * FUNCTION:    ramdisk_clear
 *
 * DESCRIPTION: 
 *              
 * Inputs:      
 *              unsigned long lba
 *              unsigned long cnt
 * Outputs:     
 *              
 * Return:      
 *              
 * Notes:       
 *              
 ******************************************************************************/
USTC_U16 ramdisk_clear(unsigned long lba, unsigned long cnt)
{
	ustc_memset(g_ramdisk.blk+lba, 0, cnt*512);

	return 0;
}
